package com.stefanie.study.sp;

import lombok.Data;

/**
 * @author: stefanie-zy
 * @time: 2024/6/27-13:38
 * @description: 饿汉式|懒汉式折中优化方法
 */
@Data
public class UserC {

    // 属性
    private String name;
    private Integer age;
    private String address;

    // 私有化构造方法
    private UserC() {
        this.name = "Stefanie-Zy";
        this.address = "陕西省西安市";
        this.age = 1;
    }

    // 内部类创建单例对象返回给外部调用使用
    private static class HolderUser {
        private final static UserC user = new UserC();
    }

    // 对外提供方法
    public static UserC getInstance() {
        return HolderUser.user;
    }
}
